package proxy

import (
	"errors"
)

type tSecureOrderService struct {
	mOrderService IOrderService
}

var gErrorPermissionDenied = errors.New("permission denied")

func NewSecureOrderService(service IOrderService) IOrderService {
	return &tSecureOrderService{
		mOrderService: service,
	}
}

func (me *tSecureOrderService) Load(id int) (error, *Order) {
	return me.mOrderService.Load(id)
}

func (me *tSecureOrderService) Save(it *Order, user IUser) error {
	if !user.Allowed("order.save") {
		return gErrorPermissionDenied
	}

	return me.mOrderService.Save(it, user)
}

func (me *tSecureOrderService) Delete(id int, user IUser) error {
	if !user.Allowed("order.delete") {
		return gErrorPermissionDenied
	}

	return me.mOrderService.Delete(id, user)
}